<?php 
	session_start();
	include('function/connection.php');
	include('function/function.php');
	
	if(isset($_GET['action']) && $_GET['action'] == "insert"){
		$cat=$_POST['txtcategory'];	
		$des=$_POST['txtdes'];
		if($cat==""){
			pageRedirect("index.php?page=category_list&action=category_new&","Please select category..!");
		}else{
			
			$sql="INSERT INTO tbl_category (cat_name,description)
			VALUES(
				'$cat',
				'$des')";
		
			$result = mysql_query($sql);
			if($result){
				pageRedirect("index.php?page=category_list&action=category_new&","Inserted successful...!");
			}
		}
	}
	
	if(isset($_GET['action']) && $_GET['action'] == "update"){
		$sql= "UPDATE tbl_category SET
				cat_name = '".$_POST['txtcategory']."',
				description = '".$_POST['txtdes']."'
			    WHERE cat_id = $_GET[cat_id]";
		$result = mysql_query($sql);
		if($result){
			pageRedirect("index.php?page=category_list&action=category_list&","Updated successful....!");
		}
	}
	if(isset($_GET['action']) && $_GET['action'] == "delete"){
		$sql = "DELETE FROM tbl_category
				WHERE cat_id = $_GET[cat_id]";
		$result = mysql_query($sql);
		if($result){
			
			//delete product name
			$sql = "DELETE FROM tbl_products
				WHERE cat_id = $_GET[cat_id]";
			$result = mysql_query($sql);
			if($result){
				//delete from stock avail
				$sql = "DELETE FROM tbl_stocks_available
				WHERE cat_id =$_GET[cat_id]";
				$result = mysql_query($sql);
				if($result){
					pageRedirect("index.php?page=category_list&action=category_list&","Deleted successful....!");
				}
			}
		}
	}
?>